package com.meisupic.copyright.repo;

import com.meisupic.copyright.domain.po.VipMemberPo;
import com.meisupic.copyright.domain.vo.VipUserVo;
import java.util.Date;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
 * @Author lanjian
 * @Date 2018/3/11 下午3:20
 */
public interface VipMemberRepo extends JpaRepository<VipMemberPo, Long>,
    JpaSpecificationExecutor<VipMemberPo> {

  List<VipMemberPo> findByUserId(Long userId);

  List<VipMemberPo> findVipMemberPosByExpiryDateAfterAndUserId(Date currDate, Long userId);

  @Query(value = "SELECT new com.meisupic.copyright.domain.vo.VipUserVo(t2.authName,t2.mobile,"
      + "t1.price,t1.createDate,t1.expiryDate,t1.memberCategoryName) from"
      + " VipMemberPo t1 , RealNameAuth t2 where t1.userId = t2.creatorId ",
      countQuery = "select count(t2.authName) FROM VipMemberPo t1,RealNameAuth t2 where t1.userId = t2.creatorId ")
  Page<VipUserVo> findVipUser(Pageable pageable);
}
